<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../lib/Validform/5.3.2/style.css" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../ht-css/Project.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js?rev=@@hash"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css"/>
    <title></title>
</head>
<body>
<form id="updataManagerForm">
    <div class="cl clearfix pl-20 pt-15">
        <label class="form-label f-l text-r" id="idAndName"></label>
    </div>
    <div class="cl clearfix pl-20 pt-15">
        <div style="position: relative">
            <input style="width: 200px;" type="text" autocomplete="off" class="input-text radius" placeholder="请输入工号/姓名进行选择" oninput="myFunction()" id="username">
            <ul class="relation radius guanlian" id="tuan">
                <li>无数据</li>
            </ul>
        </div>
    </div>
    <div class="cl clearfix pl-20 pt-15">
        <label class="form-label f-l text-r">所属部门：<span id="department"></span></label>
    </div>
    <div class="cl clearfix pl-20 pt-15">
        <label class="form-label f-l text-r">所属角色：<span id="role"></span></label>
    </div>
    <div class="text-c pd-20">
        <button class="btn btn-primary radius" onclick="btnSure()" type="button">&nbsp;&nbsp;确认&nbsp;&nbsp;</button>
        <button onclick="cancel();" class="btn radius ml-20" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
    </div>
</form>
</body>
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui/js/H-ui.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui.admin/js/H-ui.admin.js?rev=@@hash"></script> <!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../lib/Validform/5.3.2/Validform_v5.3.2_min.js?rev=@@hash"></script>
<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
<script src="../../ht-js/Project.js?rev=@@hash"></script>
<script>
    var editData = JSON.parse(sessionStorage.getItem("editData"));
    $("#idAndName").html(editData.categoryCode+" "+editData.category_name);
    
    function cancel() {
    	parent.layer.closeAll();
    }
    
    //获取光标
	$("#username").focus(function () {
	    $("#tuan").show();
        myFunction();
	});
	$(document).bind("click",function(e){
	    //id为menu的是菜单，id为open的是打开菜单的按钮
	    if($(e.target).closest("#tuan").length == 0 && $(e.target).closest("#username").length == 0){
	        //点击id为menu之外且id不是不是open，则触发
	        $("#tuan").hide()
	    }
	});
	
	//用户名及姓名查询
	function myFunction(){
	    var user_data = {
	        keywords:$("#username").val()
	    }
	    var succCallBack = function (data, status, response) {
	        if(data.userName !=""){
	            var jsonObj =data.userList;
	            if(jsonObj==""){
	                $("#tuan").html("<li>无数据</li> ");
	            }else {
	                var optionstring = "";
	                for (var  i= 0; i < jsonObj.length; i++) {
	                    var departMents = '';
	                    if (jsonObj[i].DEPARTMENT_NAME == null || jsonObj[i].DEPARTMENT_NAME == '' || jsonObj[i].DEPARTMENT_NAME == undefined){
                            departMents = '';
                        } else {
                            departMents = jsonObj[i].DEPARTMENT_NAME;
                        }

                        var roleName = '';
	                    if (jsonObj[i].ROLE_NAMES == null || jsonObj[i].ROLE_NAMES == '' || jsonObj[i].ROLE_NAMES ==  undefined){
                            roleName = '';
                        } else {
                            roleName = jsonObj[i].ROLE_NAMES;
                        }
	                    optionstring += "<li onclick='addCodeFun(this.innerHTML,\""+ departMents+ "\",\""+ roleName +"\",\""+jsonObj[i].USER_ID+"\")'>"+ jsonObj[i].NAME +"</li>";
	                }
	                $("#tuan").html(optionstring);
	            }
	        }else{
	            $("#tuan").html("<li>无数据</li> ");
	        }
	    }
	    web.doAjax(root.goodsInter.goods_listUsersJL,'post',user_data, succCallBack);
	}
    var queryData = {};
	function addCodeFun(name,departmentName,roleName,USER_ID) {
        $("#username").val(name);
        $("#department").html(departmentName);
        $("#role").html(roleName);
        $("#tuan").hide();
        if(editData.id == 1){
            queryData = {
                "categoryId":editData.categoryId,
                "parentId":editData.parentId,
                "buyId":USER_ID,
                "salesId":editData.salesId,
                "categoryLevel":editData.categoryLevel,
                "categoryCode":editData.categoryCode,
                "categoryName":editData.category_name
            }
        }else if(editData.id == 2) {
            queryData = {
                "categoryId":editData.categoryId,
                "parentId":editData.parentId,
                "buyId":editData.buyId,
                "salesId":USER_ID,
                "categoryLevel":editData.categoryLevel,
                "categoryCode":editData.categoryCode,
                "categoryName":editData.category_name
            }
        }

	}
    function btnSure() {
        console.log(queryData)
        $.ajax({
            contentType: "application/json",
            type: "POST",
            url: root.goodsInter.goods_updateUserInfor,
            cache: false, //禁用缓存
            dataType: "json",
            data: JSON.stringify(queryData),
            success: function(result) {
                console.log(result);
                if(result.errorCode == 0){
                    layer.msg("修改成功", {icon: 6, time: 1000}, function () {
                        window.parent.cx_list();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(result.message, {icon: 6, time: 1000}, function () {
                        var index =  parent.location.reload();
                        parent.layer.close(index);
                    });
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest);
            }
        });
    }
</script>
</html>